package com.wingsboat;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;
import java.util.stream.Stream;

/**
 * @author wangzhong
 * @description: TODO
 * @date 2024/7/20 21:08
 */
public class Test11 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int start = scanner.nextInt();
        int size = scanner.nextInt();
        int a = 0;
        String s = null;
        dictNode[] dictNodes = new dictNode[24];
        while(a < size){
            if(a==start) {
                s = scanner.next();
            }else{
                String s2=scanner.next();
                int index = s2.charAt(0)-'a';
                if(dictNodes[index]==null){
                    dictNode dictNode = new dictNode();
                    dictNode.addNode(s2);
                    dictNodes[index] = dictNode;
                }else{
                    dictNodes[index].addNode(s2);
                }
            }
            a = a+1;
        }
        StringBuilder sb = new StringBuilder(s);
        String next = s;
        while(true){
            int index = next.charAt(next.length()-1) - 'a';
            next = dictNodes[index] == null ? null : dictNodes[index].getMax();
            if(next == null) break;
            sb.append(next);
        }
        System.out.println(sb);

    }
}

class dictNode{
    public String key;

    public List<Node11> list = new ArrayList<>();

    public void addNode(String str){
        Node11 node = new Node11(str);
        list.add(node);
    }

    public String getMax() {
        Optional<Node11> max = list.stream().max(Node11::compareTo);
        if(max.isPresent()){

            Node11 node11 = max.get();
            list.remove(node11);
            return node11.value;
        }
        return null;
    }
}

class Node11 implements Comparable<Node11>{
    public int length;

    public int weight;

    public char start;

    public String value;

    public Node11(String str){
        this.value = str;
        this.length = str.length();
        this.start = str.charAt(0);
        for(int i =0;i<str.length();i++){
            this.weight+=('z'-str.charAt(i));
        }
    }

    @Override
    public int compareTo(Node11 o) {
        if(length>o.length) return 1;
        if(length<o.length) return -1;
        if(weight>o.weight) return 1;
        if(weight<o.weight) return -1;
        return 0;
    }
}
